package cn.icanci.loopstack.ddk.client.repository;

import java.lang.reflect.Field;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * 字段持有者
 * 
 * @author icanci
 * @since 1.0 Created in 2023/01/13 23:41
 */
public class FieldHolder {
    /**
     * 字段
     */
    private Field    field;
    /**
     * 字段类型
     */
    private Class<?> fieldClass;
    /**
     * 配置key值
     */
    private String   ddkKey;
    /**
     * 字段值：显示值，非实际值
     */
    private String   value;
    /**
     * 字段对应的对象
     */
    private Object   bean;

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public Class<?> getFieldClass() {
        return fieldClass;
    }

    public void setFieldClass(Class<?> fieldClass) {
        this.fieldClass = fieldClass;
    }

    public String getDdkKey() {
        return ddkKey;
    }

    public void setDdkKey(String ddkKey) {
        this.ddkKey = ddkKey;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Object getBean() {
        return bean;
    }

    public void setBean(Object bean) {
        this.bean = bean;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        FieldHolder that = (FieldHolder) o;
        return Objects.equals(field, that.field) && Objects.equals(fieldClass, that.fieldClass) && Objects.equals(ddkKey, that.ddkKey) && Objects.equals(value, that.value)
               && Objects.equals(bean, that.bean);
    }

    @Override
    public int hashCode() {
        return Objects.hash(field, fieldClass, ddkKey, value, bean);
    }

    @Override
    public String toString() {
        return new StringJoiner(",").add("field=" + field).add("fieldClass=" + fieldClass).add("ddkKey=" + ddkKey).add("value=" + value).add("bean=" + bean).toString();
    }
}
